/*入口主文件*/
import fun from './fun';
import '../css/style.css';



var answer = 0;
var count = 0;

var ele_start = document.getElementById('start');
ele_start.onclick = function () { //开始
    //生成随机数字
    var rand = fun.getRandomNum(0, 100);
    if (rand) {
        answer = rand;
        alert('随机数字已经生成！');
        count = 0;
    }
};




var ele_commit = document.getElementById('commit');
ele_commit.onclick = function(){
    if(!answer){
        alert('请先点击开始');
        return false;
    }
    var num = document.getElementById('number').value;
    if(!num){
        alert('input error');
        return false;
    }
    console.log('用户输入：'+num);
    var flag = fun.checkNum(answer,num);
    console.log(flag);
    count++;
    if(flag == 'ok'){
        alert('恭喜，回答正确！,一共猜了'+count+'次');
    }else if(flag == 'more'){
        alert('比正确答案大了');
    }else if(flag == 'less'){
        alert('比正确答案小了');
    }
}

var ele_show = document.getElementById('answer');
ele_show.onclick = function(){
    if(!answer){
        alert('请先开始游戏');
        return false;
    }
    alert('正确答案是：'+answer);
    answer = 0;
}




















/*
var element = document.createElement('div');
element.innerHTML = "main";
document.body.appendChild(element);*/
